
// node-apiclient 组件适配器
export namespace apiclientWrapper {
    const TraceId = "X-Request-Id";
    const RequestDepth = "X-Request-Depth";
    const AccessToken = 'X-Request-token';
    const UserId = 'X-Request-uid';
    const UserTraceId = 'X-Request-utid';
    const RealIp = 'X-Real-IP'
    const localKey = 'gd-api-client-local-storage';
    const localDepthKey = 'gd-api-client-local-storage-depth';

    const ReqId = "current-request-id";
    const LocalIp = "local-ip";
    const ClientIp = "client-ip";
    const RequestPath = "request-url";
    const RequestHost = "request-host";

    function getContext(): any {
        var p = process as any;
        var context = p.namespaces && p.namespaces[localKey];
        if (context) {
            context = context.active;
        }
        context = context || {};
        return context;
    }
    export function getTraceId(): any {
        return getContext()[TraceId]
    }
    export function getDepth(): any {
        return getContext()[RequestDepth]
    }
    export function getAccessToken(): any {
        return getContext()[AccessToken]
    }
    export function getuid(): any {
        return getContext()[UserId]
    }
    export function getutid(): any {
        return getContext()[UserTraceId]
    }
    export function getstid(): any {
        return getContext()[ReqId]
    }
    export function getLocalIp(): any {
        return getContext()[LocalIp]
    }
    export function getClentIp(): any {
        return getContext()[ClientIp]
    }
    export function getRealIp() {
        return getContext()[RealIp]
    }
    export function getRequestUrl(): any {
        return getContext()[RequestPath]
    }
    export function getRequestHost(): any {
        return getContext()[RequestHost]
    }
}